package com.group3.controller.adminController;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.group3.controller.Validated.Add;
import com.group3.controller.Validated.Select;
import com.group3.controller.Validated.Update;
import com.group3.domain.Teacher;
import com.group3.pojo.receive.TeacherReceive;
import com.group3.service.ATeacherService;
import com.group3.utils.Result;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * ATeacherController
 *
 * @author HY
 * 2021/06/03 19:04
 **/


@Api(tags = "管理员接口")
@RestController
@RequestMapping("/admin/teacher")
public class ATeacherController {

    @Resource
    private ATeacherService aTeacherService;

    //    管理员增加教师信息
    @PostMapping(value = "/addTeacher")
    @ApiOperation(value = "增加教师信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "teacherId", value = "教师工号", required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "teacherName", value = "教师姓名", required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "sex", value = "教师性别", required = true,
//                    dataType = "Integer"),
//            @ApiImplicitParam(name = "cardId", value = "教师身份证号", required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "tel", value = "教师电话号码", required = true,
//                    dataType = "String"),
//            @ApiImplicitParam(name = "position", value = "教师职位", required = true,
//                    dataType = "String"),
//    })
    @ApiOperationSupport(ignoreParameters =
            {"beforeTeacherId", "pageNumber", "pageSize"})
    public Result addTeacher(
            @Validated(Add.class) @RequestBody TeacherReceive teacherReceive) {

        return aTeacherService.insertTeacher(teacherReceive);
    }

    //    管理员根据条件查找教师
    @GetMapping(value = "")
    @ApiOperation(value = "根据条件查找教师"  )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacherId", value = "教师工号",
                    dataType = "String"),
            @ApiImplicitParam(name = "teacherName", value = "教师姓名",
                    dataType = "String"),
            @ApiImplicitParam(name = "sex", value = "教师性别",
                    dataType = "Integer"),
            @ApiImplicitParam(name = "cardId", value = "教师身份证号",
                    dataType = "String"),
            @ApiImplicitParam(name = "position", value = "教师职位",
                    dataType = "String"),
            @ApiImplicitParam(name = "status", value = "教师状态",
                    dataType = "String"),
    })
    public Result<List<Teacher>> selectTeacher(@Validated(Select.class) TeacherReceive teacherReceive) {

        return aTeacherService.selectTeacher(teacherReceive);
    }

    //    管理员根据教师工号修改教师信息
    @PutMapping(value = "/putTeacherInfo"  )
    @ApiOperation(value = "根据教师工号修改教师信息"  )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacherId", value = "修改后的教师工号",
                    dataType = "String"),
            @ApiImplicitParam(name = "beforeTeacherId", value = "原来的教师工号", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "teacherName", value = "教师姓名",
                    dataType = "String"),
            @ApiImplicitParam(name = "sex", value = "教师性别",
                    dataType = "Integer"),
            @ApiImplicitParam(name = "cardId", value = "教师身份证号",
                    dataType = "String"),
            @ApiImplicitParam(name = "tel", value = "教师手机号码",
                    dataType = "String"),
            @ApiImplicitParam(name = "position", value = "教师职位",
                    dataType = "String"),
    })
    public Result updateTeacher(
            @Validated({Update.class}) @RequestBody TeacherReceive teacherReceive) {

        return aTeacherService.updateTeacherInfo(teacherReceive);
    }

    //    管理员根据教师工号修改教师状态
    @PutMapping(value = "/putStatus")
    @ApiOperation(value = "根据教师工号修改教师状态"  )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacherId", value = "教师工号", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "status", value = "教师状态", required = true,
                    dataType = "Integer"),
    })
    public Result updateTeacherStatus(
            @NotEmpty @RequestParam Integer status, @NotEmpty @RequestParam String teacherId) {

        return aTeacherService.updateTeacherStatus(status, teacherId);
    }


    @GetMapping(value = "/isExistTeacherId")
    @ApiOperation(value = "判断教师工号是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacherId", value = "教师工号", required = true,
                    dataType = "String"),
    })
    public Result existTeacherId(@NotEmpty @RequestParam String teacherId) {

        return aTeacherService.isExistTeacherId(teacherId);
    }

    @GetMapping(value = "/isExistTeacherCardId")
    @ApiOperation(value = "判断教师身份证号是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "教师身份证号", required = true,
                    dataType = "String"),
    })
    public Result existTeacherCardId(@NotEmpty @RequestParam String cardId) {

        return aTeacherService.isExistTeacherCardId(cardId);
    }
}
